package com.train.trainmanage.serviceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.train.trainmanage.mapper.StationModelMapper;
import com.train.trainmanage.model.StationModel;
import com.train.trainmanage.service.StationService;

@Service
public class StationServiceImpl implements StationService{
	
	@Autowired
	private StationModelMapper stationMapper;

	@Override
	public List<StationModel> getAllStation() {
		List<StationModel> result = stationMapper.listAllStation();
		return result;
	}

	@Override
	public StationModel getById(Integer stationId) {
		StationModel station = stationMapper.selectByPrimaryKey(stationId);
		return station;
	}

	@Override
	public StationModel getByName(String stationName) {
		StationModel result = new StationModel();
		if(stationName != null && stationName.length() >0) {
			result = stationMapper.selectByName(stationName);
		}
		return result;
	}

	@Override
	public int saveStation(StationModel station) {
		Integer stationId = station.getStationId();
		int result = 0;
		if(stationId != null && stationId > 0) {
			result = stationMapper.updateByPrimaryKeySelective(station);
		}else {
			result = stationMapper.insertSelective(station);
		}
		return result;
	}

}
